package com.vf.admin.utils.chouJiang;

import java.util.List;

/**
 * @author: 你猜
 * @time：2021/5/27 19:58
 */
public class Test1 {
/*
    public static void main(String[] args) {

        List<Award> awardList = new ArrayList<Award>();
        Award award1 = new Award();
        award1.setAwardName("手机");//10%
        award1.setProbability(0.1);
        awardList.add(award1);

        Award award2 = new Award();
        award2.setAwardName("水杯");//20%
        award2.setProbability(0.2);//概率加上上一个奖品的概率（累加）
        awardList.add(award2);


        Award award3 = new Award();
        award3.setAwardName("耳机");//10%
        award3.setProbability(0.3);
        awardList.add(award3);


        Award award4 = new Award();
        award4.setAwardName("鼠标");//10%
        award4.setProbability(0.4);
        awardList.add(award4);

        Award award6 = new Award();
        award6.setAwardName("战斗机");//60%
        award6.setProbability(0.5);//最后一个肯定是1
        awardList.add(award6);


        Award award5 = new Award();
        award5.setAwardName("谢谢惠顾");//60%
        award5.setProbability(1d);//最后一个肯定是1
        awardList.add(award5);


        Random random = new Random();
        int a = 0,b = 0,c = 0,d = 0,e = 0,f = 0;
        for (int i = 0; i < 10000; i++) {

            Double userSelect = random.nextDouble();//0.0-1.0的double随机数（不包括1.0）
            String awardName = duageAward(userSelect, awardList);
            //信息统计
            if ("手机".equals(awardName)) {
                a++;
            }else if ("水杯".equals(awardName)) {
                b++;
            }else if ("耳机".equals(awardName)) {
                c++;
            }else if ("鼠标".equals(awardName)){
                d++;
            }else if ("战斗机".equals(awardName)){
                e++;
            }else if ("谢谢惠顾".equals(awardName)){
                f++;
            }
        }
        System.out.println("手机 " + a + " 次");
        System.out.println("水杯 " + b + " 次");
        System.out.println("耳机 " + c + " 次");
        System.out.println("鼠标 " + d + " 次");
        System.out.println("战斗机 " + e + " 次");
        System.out.println("谢谢惠顾 " + f + " 次");
    }*/

    /**
     * 选奖品
     * @param userSelect
     * @param awardList
     * @return
     */
    public static Integer duageAward(Double userSelect, List<Award> awardList){
        System.out.println("==============================");

        for (Award award : awardList) {
            System.out.println("------------");
            System.out.println(userSelect);
            System.out.println(award.getProbability());
            System.out.println(userSelect < award.getProbability());
            System.out.println("------------");

            if(userSelect < award.getProbability()){
                return award.getAwardName();
            }
        }
        return null;
    }

    /**
     * 选奖品-修改
     * @param userSelect
     * @param awardList
     * @return
     */
    public static Integer duageAwardInteger(Integer userSelect, List<Award> awardList){
        System.out.println("==============================");

        for (Award award : awardList) {
            System.out.println("------------");
            System.out.println(userSelect);
            System.out.println(award.getProbabilityNum());
            System.out.println(userSelect < award.getProbabilityNum());
            System.out.println("------------");

            if(userSelect < award.getProbabilityNum()){
                return award.getAwardName();
            }
        }
        return null;
    }
}
